<template>
  <RadioGroup size="small"  >
    <RadioButton :disabled="!doc && !link && !markdownDoc && !codeDoc" @click="handleClick">
      预览
    </RadioButton>
    <RadioButton :disabled="!link" @click="handleLocation">
      跳转
    </RadioButton>
  </RadioGroup>
  <IFrameModal @register="registerIFrameModal"/>
</template>
<script lang="ts" setup>
import IFrameModal from "@/components/IFrameModal/index.vue";
import {useModal} from '@/components/Modal';
import {RadioButton,RadioGroup} from 'ant-design-vue'

const [registerIFrameModal, {openModal: openIFrameModal}] = useModal();
const props = defineProps({
  fullScreen: {
    type: Boolean,
    default: false,
  },
  doc: {
    type: Object,
    default: null,
  },
  link:{
    type: Object,
    default: null,
  },
  markdownDoc:{
    type: Object,
    default: null,
  },
  codeDoc:{
    type: Object,
    default: null,
  },
  codeMode:{
    type: String,
    default: 'javascript',
  },
  codeTheme:{
    type: String,
    default: 'github',
  }
});
const handleClick = () => {
  openIFrameModal(true, {
    modalTitle: '预览',
    modalWidth: 900,
    modalMinHeight: 600,
    fullScreen: props.fullScreen,
    iframeSrcDoc: props.doc,
    iframeSrc: props.link,
    markdownDoc: props.markdownDoc,
    codeDoc: props.codeDoc,
    codeMode: props.codeMode,
    codeTheme: props.codeTheme,
  });
}

const handleLocation = () => {
  // 新开窗口跳转
  window.open(props.link);
}

</script>
